package com.vcc.service.client.vo.card;

import cn.hutool.json.JSONUtil;
import com.vcc.core.util.JsonUtil;
import com.vcc.data.entity.CardType;
import com.vcc.data.entity.UserCardWallet;
import com.vcc.service.boss.share.config.response.BossShareAccountConfigResponse;
import com.vcc.service.client.vo.baseVo.BaseVo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Getter
@Setter
public class CardTypeVo extends BaseVo implements Serializable {
    private String sectionNo;
    private String code;
    private String currency;
    private String currencyName;
    private String remark;
    private Integer verifyOpenCardStatus;
    private Integer verifyRechargeCardStatus;
    private Integer verifyUpdateLimitStatus;
    private Integer verifyOutCardStatus;
    private Integer verifyCloseCardStatus;
    private Integer verifyFreezeUnFreezeCardStatus;
    private String cardLabel;
    private String channelName;
    private Integer status;
    private Integer verifySpecialStatus;
    private BigDecimal amount;
    private BigDecimal exchangeRate;
    private Integer openCardOnLineCount;
    private BigDecimal openCardRechargeMinAmount;
    private BigDecimal withdrawMinAmount;
    private BigDecimal rechargeMinAmount;
    private BigDecimal closeCardMinAmount;
    private String withdrawStatus;
    private String closeStatus;
    private BigDecimal authFee;
    private BigDecimal authFeeRate;
    private BigDecimal minAuthFee;
    private BigDecimal minAuthFeeRate;
    private BigDecimal failFee;
    private BigDecimal failFeeRate;
    private BigDecimal refundFee;
    private BigDecimal refundFeeRate;
    private BigDecimal reversalFee;
    private BigDecimal reversalFeeRate;
    private BigDecimal crossBorderFee;
    private BigDecimal crossBorderFeeRate;
    private String country;
    private List<String> cardScenes;
    private String type;

    public CardTypeVo() {
    }

    public CardTypeVo(CardType card) {
        super.setId(card.getId());
        this.sectionNo = card.getSectionNo();
        this.code = card.getCode();
        this.currency = card.getCurrencyCode();
        this.currencyName = card.getCurrencyName();
        this.remark = card.getRemark();
        //0 支持  1  不支持  2  关闭中
        this.verifyOpenCardStatus = card.getVerifyOpenCardStatus();
        this.verifyRechargeCardStatus = card.getVerifyRechargeCardStatus();
        this.verifyOutCardStatus = card.getVerifyOutCardStatus();
        this.verifyCloseCardStatus = card.getVerifyCloseCardStatus();
        this.verifyFreezeUnFreezeCardStatus = card.getVerifyFreezeUnFreezeCardStatus();
        this.cardLabel = card.getCardLabel();
//        this.channelName = card.getChannelName();
        this.status = card.getStatus();
        this.verifySpecialStatus = card.getVerifySpecialStatus();
        this.amount = card.getAmount();
        this.exchangeRate = BigDecimal.valueOf(0);
        this.openCardOnLineCount = 20;
        this.openCardRechargeMinAmount = card.getOpenCardRechargeMinAmount();
        this.withdrawMinAmount = card.getWithdrawMinAmount();
        this.rechargeMinAmount = card.getRechargeMinAmount();
        this.closeCardMinAmount = card.getCloseCardMinAmount();
        this.withdrawStatus = card.getWithdrawStatus();
        this.closeStatus = card.getCloseStatus();
        this.authFee = BigDecimal.ZERO;
        this.authFeeRate = BigDecimal.ZERO;
        this.minAuthFee = BigDecimal.ZERO;
        this.minAuthFeeRate = BigDecimal.ZERO;
        this.failFee = BigDecimal.ZERO;
        this.failFeeRate = BigDecimal.ZERO;
        this.refundFee = BigDecimal.ZERO;
        this.refundFeeRate = BigDecimal.ZERO;
        this.reversalFee = BigDecimal.ZERO;
        this.reversalFeeRate = BigDecimal.ZERO;
        this.crossBorderFee = BigDecimal.ZERO;
        this.crossBorderFeeRate = BigDecimal.ZERO;
        this.country = card.getCountry();
        this.cardScenes = StringUtils.isNotBlank(card.getCardScenes()) ? JSONUtil.toList(card.getCardScenes(), String.class) : List.of();
        this.type = card.getType();
    }

    public CardTypeVo(CardType card, UserCardWallet userCardWallet) {
        super.setId(card.getId());
        this.sectionNo = card.getSectionNo();
        this.code = card.getCode();
        this.currency = card.getCurrencyCode();
        this.currencyName = card.getCurrencyName();
        this.remark = card.getRemark();
        //0 支持  1  不支持  2  关闭中
        this.verifyOpenCardStatus = setValue(card.getVerifyOpenCardStatus(), userCardWallet.getVerifyOpenCardStatus());
        this.verifyRechargeCardStatus = setValue(card.getVerifyRechargeCardStatus(), userCardWallet.getVerifyRechargeCardStatus());
        this.verifyOutCardStatus = setValue(card.getVerifyOutCardStatus(), userCardWallet.getVerifyOutCardStatus());
        this.verifyCloseCardStatus = setValue(card.getVerifyCloseCardStatus(), userCardWallet.getVerifyCloseCardStatus());
        this.verifyFreezeUnFreezeCardStatus = setValue(card.getVerifyFreezeUnFreezeCardStatus(), userCardWallet.getVerifyFreezeUnFreezeCardStatus());
        this.cardLabel = card.getCardLabel();
        this.channelName = card.getChannelName();
        this.status = card.getStatus();
        this.verifySpecialStatus = card.getVerifySpecialStatus();
        this.amount = userCardWallet.getAmount();
        this.exchangeRate = userCardWallet.getExchangeRate();
        this.openCardOnLineCount = userCardWallet.getOpenCardOnLineCount();
        this.openCardRechargeMinAmount = card.getOpenCardRechargeMinAmount();
        this.withdrawMinAmount = card.getWithdrawMinAmount();
        this.rechargeMinAmount = card.getRechargeMinAmount();
        this.closeCardMinAmount = card.getCloseCardMinAmount();
        this.withdrawStatus = card.getWithdrawStatus();
        this.closeStatus = card.getCloseStatus();
        this.authFee = userCardWallet.getAuthFee();
        this.authFeeRate = userCardWallet.getAuthFeeRate();
        this.minAuthFee = userCardWallet.getMinAuthFee();
        this.minAuthFeeRate = userCardWallet.getMinAuthFeeRate();
        this.failFee = userCardWallet.getFailFee();
        this.failFeeRate = userCardWallet.getFailFeeRate();
        this.refundFee = userCardWallet.getRefundFee();
        this.refundFeeRate = userCardWallet.getRefundFeeRate();
        this.reversalFee = userCardWallet.getReversalFee();
        this.reversalFeeRate = userCardWallet.getReversalFeeRate();
        this.crossBorderFee = userCardWallet.getCrossBorderFee();
        this.crossBorderFeeRate = userCardWallet.getCrossBorderFeeRate();
        this.country = card.getCountry();
        this.cardScenes = StringUtils.isNotBlank(card.getCardScenes()) ? JSONUtil.toList(card.getCardScenes(), String.class) : List.of();
        this.type = card.getType();


    }

    public CardTypeVo(CardType card, BossShareAccountConfigResponse bossShareAccountConfigResponse) {
        super.setId(card.getId());
        this.sectionNo = card.getSectionNo();
        this.code = card.getCode();
        this.currency = card.getCurrencyCode();
        this.currencyName = card.getCurrencyName();
        this.remark = card.getRemark();
        //0 支持  1  不支持  2  关闭中
        this.verifyOpenCardStatus = setValue(card.getVerifyOpenCardStatus(), bossShareAccountConfigResponse.getVerifyOpenCardStatus());
        this.verifyUpdateLimitStatus = setValue(card.getVerifyRechargeCardStatus(), bossShareAccountConfigResponse.getVerifyUpdateLimitStatus());
        this.verifyCloseCardStatus = setValue(card.getVerifyCloseCardStatus(), bossShareAccountConfigResponse.getVerifyCloseCardStatus());
        this.verifyFreezeUnFreezeCardStatus = setValue(card.getVerifyFreezeUnFreezeCardStatus(), bossShareAccountConfigResponse.getVerifyFreezeUnFreezeCardStatus());
        this.cardLabel = card.getCardLabel();
        this.channelName = card.getChannelName();
        this.status = card.getStatus();
        this.verifySpecialStatus = card.getVerifySpecialStatus();
        this.amount = bossShareAccountConfigResponse.getAmount();
        this.openCardRechargeMinAmount = card.getOpenCardRechargeMinAmount();
        this.withdrawMinAmount = card.getWithdrawMinAmount();
        this.rechargeMinAmount = card.getRechargeMinAmount();
        this.closeCardMinAmount = card.getCloseCardMinAmount();
        this.withdrawStatus = card.getWithdrawStatus();
        this.closeStatus = card.getCloseStatus();
        this.authFee = bossShareAccountConfigResponse.getAuthFee();
        this.authFeeRate = bossShareAccountConfigResponse.getAuthFeeRate();
        this.minAuthFee = bossShareAccountConfigResponse.getMinAuthFee();
        this.minAuthFeeRate = bossShareAccountConfigResponse.getMinAuthFeeRate();
        this.failFee = bossShareAccountConfigResponse.getFailFee();
        this.failFeeRate = bossShareAccountConfigResponse.getFailFeeRate();
        this.refundFee = bossShareAccountConfigResponse.getRefundFee();
        this.refundFeeRate = bossShareAccountConfigResponse.getRefundFeeRate();
        this.reversalFee = bossShareAccountConfigResponse.getReversalFee();
        this.reversalFeeRate = bossShareAccountConfigResponse.getReversalFeeRate();
        this.crossBorderFee = bossShareAccountConfigResponse.getCrossBorderFee();
        this.crossBorderFeeRate = bossShareAccountConfigResponse.getCrossBorderFeeRate();
        this.country = card.getCountry();
        this.cardScenes = StringUtils.isNotBlank(card.getCardScenes()) ? JSONUtil.toList(card.getCardScenes(), String.class) : List.of();
        this.type = card.getType();

    }

    private Integer setValue(Integer cardSwitch, Integer userCardWalletSwitch) {
        if (cardSwitch == 0) {
            return userCardWalletSwitch;
        } else if (cardSwitch == 1) {
            return 1;
        } else {
            return 2;
        }
    }

}
